package org.yq.wsclient;

import java.lang.reflect.Field;


public class FieldValueFactory {
	 
	public static void setFieldValue(Field field ,Object obj,String val) throws Exception{
		if(field.getType().equals(Integer.class)){
			field.set(obj, new Integer(Integer.valueOf(val)));
		}else if(field.getType().equals(Float.class)){
			field.set(obj, new Float(Float.valueOf(val)));
		}else if(field.getType().equals(Double.class)){
			field.set(obj, new Double(Double.valueOf(val)));
		}else if(field.getType().equals(Boolean.class)){
			field.set(obj, new Boolean(Boolean.valueOf(val)));
		}else if(field.getType().equals(Byte.class)){
			field.set(obj, new Byte(Byte.valueOf(val)));
		}else if(field.getType().equals(Long.class)){
			field.set(obj, new Long(Long.valueOf(val)));
		}else if("int".equals(field.getType().toString())){
			field.setInt(obj, Integer.parseInt(val));
		}else if("boolean".equals(field.getType().toString())){
			field.setBoolean(obj, Boolean.parseBoolean(val));
		}else if("byte".equals(field.getType().toString())){
			field.setByte(obj, Byte.parseByte(val));
		}else if("double".equals(field.getType().toString())){
			field.setDouble(obj, Double.parseDouble(val));
		}else if("float".equals(field.getType().toString())){
			field.setFloat(obj, Float.parseFloat(val));
		}else if("long".equals(field.getType().toString())){
			field.setLong(obj, Long.parseLong(val));
		}else if("short".equals(field.getType().toString())){
			field.setShort(obj, Short.parseShort(val));
		}else{
			field.set(obj, val);
		}
	}
}
